(function($){
	var doClick = function(){
		var that = $(this)
		var ob = $(this).data('op');
		$.post('/op',{op:ob},function(data){
			if(data=='1'){
				var n = that.find('b');
				//alert(n.html());
				n.html(n.html()*1+1);
			}
		});
	}
	
	$('.dig a').click(doClick);
	
	$("#loadmore").click(function(){
		var btn = $(this);
		var i = $(this).attr('data-last');
		
		$.post('/loadmore',{id:i},function(data){
			if(data=='-1'){
				btn.html('no more ');
			}else{
				var ob = JSON.parse(data);//alert(btn.data('last'));
				console.log(ob.data);
				btn.attr('data-last',ob.last);
				var html = '';
				for(var k in ob.data){
					html += '<section  class="word_block"><header><span class="date">'+(new Date(1000*ob.data[k].dateline).getMonth()+1)+'/'+(new Date(1000*ob.data[k].dateline).getDate()+1)+'</span>'+
					'<span class="glyphicon glyphicon-book"></span>'+ob.data[k].word+'</header>'+
					'<p><span class="glyphicon glyphicon-question-sign"></span>'+ob.data[k].des+'</p>'+
					'<hr><p><span class="glyphicon glyphicon-link"></span>'+ob.data[k].example+'</p>'+
					'<div class="btn-group btn-group-justified dig"><a role="button" class="btn btn-default" data-op=\'{"op":"up","id":'+ob.data[k].id+'}\'>'+
					'<span class="glyphicon glyphicon-thumbs-up"></span> 顶(<b>'+ob.data[k].up+'</b>)'+
					'</a><a role="button" class="btn btn-default" data-op=\'{"op":"down","id":'+ob.data[k].id+'}\'>'+
					'<span class="glyphicon glyphicon-thumbs-down"></span> 踩(<b>'+ob.data[k].down+'</b>)'+
					'</a></div></section>';
				}
				$("#block_list").append(html);
				$('.dig a').unbind('click').click(doClick);
			}
		});
	});
	$("#show_about,#show_box,#no_share").click(function(){
		var s = $(this).data('static');
		$.post('/static',{page:s},function(data){
			var str = data;
			$("#container").html(str);
		});
		
	});
	
	
})(jQuery);
console.log('this version is node+mysql,next version will be node+mongo,coming soon.');